<template>
  <div v-loading="loading">
    <Collocate @func="openState" v-if="state"></Collocate>
    <Trace v-else @func="openState1" :form="form"></Trace>
  </div>
</template>

<script>
import Collocate from "./Collocate/collocate";
import Trace from "./Collocate/trace";
export default {
  data() {
    return {
      state: true,
      loading: false,
      form: {},
    };
  },
  created() {
    this.getBuyTraceService();
  },
  methods: {
    async getBuyTraceService() {
      this.loading = true;
      const res = await this.axios.getBuyTraceService();
      this.loading = false;
      if (res.data.data.status == 1) {
        this.state = true;
      } else {
        this.state = false;
      }
      this.form = res.data.data;
      this.form.consumeCapacity = this.changeKB(this.form.consumeCapacity);
      this.form.totalCapacity = this.changeKB(this.form.totalCapacity*1024*1024*1024)
    },
    changeKB(i) {
      i = parseInt(i)
      if (i <= 1000) return i + "B";
      if (i / 1024 <= 1000) return (i / 1024).toFixed(2) + "KB";
      if (i / 1024 / 1024 <= 1000) return (i / 1024 / 1024).toFixed(2) + "MB";
      if (i / 1024 / 1024 / 1024 <= 1000)
        return (i / 1024 / 1024 / 1024).toFixed(2) + "G";
      return (i / 1024 / 1024 / 1024 / 1024).toFixed(2) + "T";
    },
    openState(data) {
      this.state = data;
    },
    openState1(data) {
      this.state = data;
    },
  },
  components: {
    Collocate,
    Trace,
  },
};
</script>

<style lang="scss" scoped>
</style>